<?php
namespace Api\Controller;
use Think\Controller;
class PhotoController extends CommonController {
	 public function imgphotos(){
		$shop_id = I('get.shop_id');	
		$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize   = 2 * 1024 *1024 ;// 设置附件上传大小
		$upload->exts      = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$path = realpath(__ROOT__);
		$upload->rootPath  = $path.'/Public/uploadfiles/'; // 设置附件上传根目录
		$upload->savePath  = 'uploadphotos/'; // 设置附件上传（子）目录
		// 上传文件 
		$info   =   $upload->upload();
		if(!$info) {// 上传错误提示错误信息
			$this->error($upload->getError());
		}else{// 上传成功
			$img_src = "/Public/uploadfiles/{$info['_img']['savepath']}".'/'."{$info['_img']['savename']}";
			// 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.jpg
			$image = new \Think\Image();
			$image->open("{$path}{$img_src}");
			$thumbpath = $path."/Public/uploadfiles/{$info['_img']['savepath']}";
			$image->thumb(400, 460)->save($thumbpath."mid_".$info['_img']['savename']);
			$image->thumb(220, 220,6)->save($thumbpath."min_".$info['_img']['savename']);
			$this->response(true,1,$img_src,true);
		}		
	
	}
}
